package com.shuyun.ccms.encrypt.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;
import com.shuyun.ccms.encrypt.util.ConnectionUtil;
import com.shuyun.crypt.CryptTools;

public class EncryptIncrementData {
	private static Logger logger = LoggerFactory.getLogger(EncryptIncrementData.class);
	private static final Integer COMMIT_NUMBER = 10000;
	private static final Integer CLAEN_NUMBER = 300;

	public static void encrytTaobaoData(Connection conn)throws Exception{
		PreparedStatement ps = null;
		Statement insertSt = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		StringBuffer infoSql = null;
		StringBuffer phoneSql = null;
		logger.info("增量加密淘宝客户信息开始");
		long start = System.currentTimeMillis();
		List<String> phoneList = Lists.newArrayList();
		int count = 1;
		try {
			sql.append("select ptc.customerno,full_name,mobile,phone,fullname_modified,mobile_modified,fullname_most,mobile_most,phone_most  ");
			sql.append("from plt_taobao_customer ptc  ");
			sql.append("where not exists (  ");
			sql.append("select customerno  ");
			sql.append("from tb_taobao_customer_info tc  ");
			sql.append("where  ptc.customerno  = tc.customerno)   ");
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			insertSt = conn.createStatement();
			conn.setAutoCommit(false);
			while(rs.next()){
				infoSql = new StringBuffer();
				phoneSql = new StringBuffer();

				String customerNo = rs.getString("customerno");
				String fullName = rs.getString("full_name");
				String mobile = rs.getString("mobile");
				String phone = rs.getString("phone");
				String fullNameModified = rs.getString("fullname_modified");
				String mobileModified = rs.getString("mobile_modified");
				String fullNameMost = rs.getString("fullname_most");
				String mobileMost = rs.getString("mobile_most");
				String phoneMost = rs.getString("phone_most");

				String encryptCustomerNo = null;
				String encryptFullName = null;
				String encryptMobile = null;
				String encryptPhone = null;
				String encryptFullNameModified = null;
				String encryptMobileModified = null;
				String encryptFullNameMost = null;
				String encryptMobileMost = null;
				String encryptPhoneMost = null;

				infoSql.append("insert ignore into tb_taobao_customer_info(customerno,customerno_encrypt,full_name_encrypt, mobile_encrypt,phone_encrypt,fullname_modified_encrypt,mobile_modified_encrypt,fullname_most_encrypt,mobile_most_encrypt,phone_most_encrypt)");
				infoSql.append("values('");

				if(customerNo.endsWith("~1~")){
					continue;
				}

				encryptCustomerNo = CryptTools.encrypt(customerNo, CryptTools.TYPE_NICK);
				infoSql.append(customerNo).append("','").append(encryptCustomerNo).append("',");
				if(fullName != null){
					encryptFullName = CryptTools.encrypt(fullName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullName).append("',");
				}else{
					infoSql.append(encryptFullName).append(",");
				}
				if(StringUtils.isNotBlank(mobile)){
					encryptMobile = CryptTools.encrypt(mobile, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobile).append("',");

					if(!phoneList.contains(mobile)){
						phoneList.add(mobile);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_taobao_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobile).append("','").append(encryptMobile).append("')");
						insertSt.addBatch(phoneSql.toString());
						//System.out.println("customerNo:" + customerNo + ",mobile: " + mobile + ", encryptMobile: " + encryptMobile + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobile).append(",");
				}
				if(StringUtils.isNotBlank(phone)){
					encryptPhone = CryptTools.encrypt(phone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhone).append("',");

					if(!phoneList.contains(phone)){
						phoneList.add(phone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_taobao_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phone).append("','").append(encryptPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
						// System.out.println("customerNo:" + customerNo + ",phone: " + phone + ", encryptPhone: " + encryptPhone + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhone).append(",");
				}
				if(fullNameModified != null){
					encryptFullNameModified = CryptTools.encrypt(fullNameModified, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullNameModified).append("',");
				}else{
					infoSql.append(encryptFullNameModified).append(",");
				}
				if(StringUtils.isNotBlank(mobileModified)){
					encryptMobileModified = CryptTools.encrypt(mobileModified, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobileModified).append("',");

					if(!phoneList.contains(mobileModified)){
						phoneList.add(mobileModified);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_taobao_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobileModified).append("','").append(encryptMobileModified).append("')");
						insertSt.addBatch(phoneSql.toString());
						// System.out.println("customerNo:" + customerNo + ",mobileModified: " + mobileModified + ", encryptMobileModified: " + encryptMobileModified + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobileModified).append(",");
				}
				if(fullNameMost != null){
					encryptFullNameMost = CryptTools.encrypt(fullNameMost, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullNameMost).append("',");
				}else{
					infoSql.append(encryptFullNameMost).append(",");
				}
				if(StringUtils.isNotBlank(mobileMost)){
					encryptMobileMost = CryptTools.encrypt(mobileMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobileMost).append("',");

					if(!phoneList.contains(mobileMost)){
						phoneList.add(mobileMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_taobao_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobileMost).append("','").append(encryptMobileMost).append("')");
						insertSt.addBatch(phoneSql.toString());
					 	//System.out.println("customerNo:" + customerNo + ",mobileMost: " + mobileMost + ", encryptMobileMost: " + encryptMobileMost + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobileMost).append(",");
				}
				if(StringUtils.isNotBlank(phoneMost)){
					encryptPhoneMost = CryptTools.encrypt(phoneMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhoneMost).append("')");

					if(!phoneList.contains(phoneMost)){
						phoneList.add(phoneMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_taobao_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phoneMost).append("','").append(encryptPhoneMost).append("')");
						insertSt.addBatch(phoneSql.toString());
						// System.out.println("customerNo:" + customerNo + ",phoneMost: " + phoneMost + ", encryptPhoneMost: " + encryptPhoneMost + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhoneMost).append(")");
				}
				insertSt.addBatch(infoSql.toString());
			 	//System.out.println("------------ taobao ---- count: " + count);
			 	//System.out.println("taobao infosql: " + infoSql.toString());
				if(count % COMMIT_NUMBER == 0){
					logger.info("淘宝提交数据. count: " + count);
					insertSt.executeBatch();
					conn.commit();
					insertSt.clearBatch();
					count=1;
				}
				if(count%CLAEN_NUMBER == 0){
					phoneList.clear();
				}
				count++;
			}
			insertSt.executeBatch();
			conn.commit();
			insertSt.clearBatch();
			long end = System.currentTimeMillis();
			logger.info("增量加密淘宝客户信息结束,耗时: " + (end -start)/1000 + "s");
		} catch (Exception e) {
			conn.rollback();
			e.printStackTrace();
			logger.error("加密淘宝增量数据失败. " + e.getMessage());
			throw e;
		}finally{
			phoneList.clear();
			phoneList = null;
			ConnectionUtil.newInstance().close(ps, rs);
			ConnectionUtil.newInstance().closeStatement(insertSt);
		}
	}

	public static void encrytJdData(Connection conn)throws Exception{
		PreparedStatement ps = null;
		Statement insertSt = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		StringBuffer infoSql = null;
		StringBuffer phoneSql = null;
		logger.info("增量加密京东客户信息开始");
		long start = System.currentTimeMillis();
		List<String> phoneList = Lists.newArrayList();
		int count = 1;
		try {
			sql.append("select pin,full_name,mobile,telephone  ");
			sql.append("from plt_jd_customer pjc  ");
			sql.append("where not exists (  ");
			sql.append("select customerno  ");
			sql.append("from tb_jd_customer_info tc  ");
			sql.append("where  pjc.pin  = tc.customerno)   ");
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			insertSt = conn.createStatement();
			conn.setAutoCommit(false);
			while(rs.next()){
				infoSql = new StringBuffer();
				phoneSql = new StringBuffer();

				String customerNo = rs.getString("pin");
				String fullName = rs.getString("full_name");
				String mobile = rs.getString("mobile");
				String phone = rs.getString("telephone");

				String encryptCustomerNo = null;
				String encryptFullName = null;
				String encryptMobile = null;
				String encryptPhone = null;

				infoSql.append("insert ignore into tb_jd_customer_info(customerno,customerno_encrypt,full_name_encrypt, mobile_encrypt,telephone_encrypt)");
				infoSql.append("values('");

				encryptCustomerNo = CryptTools.encrypt(customerNo, CryptTools.TYPE_NICK);
				infoSql.append(customerNo).append("','").append(encryptCustomerNo).append("',");
				if(fullName != null){
					encryptFullName = CryptTools.encrypt(fullName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullName).append("',");
				}else{
					infoSql.append(encryptFullName).append(",");
				}
				if(StringUtils.isNotBlank(mobile)){
					encryptMobile = CryptTools.encrypt(mobile, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobile).append("',");

					if(!phoneList.contains(mobile)){
						phoneList.add(mobile);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_jd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobile).append("','").append(encryptMobile).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobile).append(",");
				}
				if(StringUtils.isNotBlank(phone)){
					encryptPhone = CryptTools.encrypt(phone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhone).append("')");

					if(!phoneList.contains(phone)){
						phoneList.add(phone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_jd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phone).append("','").append(encryptPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhone).append(")");
				}
				insertSt.addBatch(infoSql.toString());
			//	System.out.println("jd infosql: " + infoSql.toString());
				if(count % COMMIT_NUMBER == 0){
					insertSt.executeBatch();
					conn.commit();
					insertSt.clearBatch();
					logger.info("京东提交客户信息数据. count: " + count);
					count=1;
				}
				if(count%CLAEN_NUMBER == 0){
					phoneList.clear();
				}
				count++;
			}
			insertSt.executeBatch();
			conn.commit();
			insertSt.clearBatch();
			long end = System.currentTimeMillis();
			logger.info("增量加密京东客户信息结束,耗时: " + (end -start)/1000 + "s");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("加密京东增量数据失败. " + e.getMessage());
			throw e;
		}finally{
			phoneList.clear();
			phoneList = null;
			ConnectionUtil.newInstance().close(ps, rs);
			ConnectionUtil.newInstance().closeStatement(insertSt);
		}
	}

	public static void encrytDdData(Connection conn)throws Exception{
		PreparedStatement ps = null;
		Statement insertSt = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		StringBuffer infoSql = null;
		StringBuffer phoneSql = null;
		logger.info("增量加密当当客户信息开始");
		long start = System.currentTimeMillis();
		List<String> phoneList = Lists.newArrayList();
		int count = 1;
		try {
			sql.append("select customerno,full_name,mobile,phone,fullname_most,mobile_most,phone_most ");
			sql.append("from plt_dd_customer pdc  ");
			sql.append("where not exists (  ");
			sql.append("select customerno  ");
			sql.append("from tb_dd_customer_info tc  ");
			sql.append("where  pdc.customerno  = tc.customerno)   ");
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			insertSt = conn.createStatement();
			conn.setAutoCommit(false);
			while(rs.next()){
				infoSql = new StringBuffer();
				phoneSql = new StringBuffer();

				String customerNo = rs.getString("customerno");
				String fullName = rs.getString("full_name");
				String mobile = rs.getString("mobile");
				String phone = rs.getString("phone");
				String fullNameMost = rs.getString("fullname_most");
				String mobileMost = rs.getString("mobile_most");
				String phoneMost = rs.getString("phone_most");

				String encryptCustomerNo = null;
				String encryptFullName = null;
				String encryptMobile = null;
				String encryptPhone = null;
				String encryptFullNameMost = null;
				String encryptMobileMost = null;
				String encryptPhoneMost = null;


				infoSql.append("insert ignore into tb_dd_customer_info(customerno,customerno_encrypt,full_name_encrypt, mobile_encrypt,phone_encrypt,fullname_most_encrypt,mobile_most_encrypt,phone_most_encrypt)");
				infoSql.append("values('");

				encryptCustomerNo = CryptTools.encrypt(customerNo, CryptTools.TYPE_NICK);
				infoSql.append(customerNo).append("','").append(encryptCustomerNo).append("',");
				if(fullName != null){
					encryptFullName = CryptTools.encrypt(fullName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullName).append("',");
				}else{
					infoSql.append(encryptFullName).append(",");
				}
				if(StringUtils.isNotBlank(mobile)){
					encryptMobile = CryptTools.encrypt(mobile, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobile).append("',");

					if(!phoneList.contains(mobile)){
						phoneList.add(mobile);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_dd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobile).append("','").append(encryptMobile).append("')");
						insertSt.addBatch(phoneSql.toString());
					//	System.out.println("customerNo:" + customerNo + ",mobile: " + mobile + ", encryptMobile: " + encryptMobile + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobile).append(",");
				}
				if(StringUtils.isNotBlank(phone)){
					encryptPhone = CryptTools.encrypt(phone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhone).append("',");

					if(!phoneList.contains(phone)){
						phoneList.add(phone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_dd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phone).append("','").append(encryptPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
						//System.out.println("customerNo:" + customerNo + ",phone: " + phone + ", encryptPhone: " + encryptPhone + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhone).append(",");
				}

				if(fullNameMost != null){
					encryptFullNameMost = CryptTools.encrypt(fullNameMost, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullNameMost).append("',");
				}else{
					infoSql.append(encryptFullNameMost).append(",");
				}
				if(StringUtils.isNotBlank(mobileMost)){
					encryptMobileMost = CryptTools.encrypt(mobileMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobileMost).append("',");

					if(!phoneList.contains(mobileMost)){
						phoneList.add(mobileMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_dd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobileMost).append("','").append(encryptMobileMost).append("')");
						insertSt.addBatch(phoneSql.toString());
						//System.out.println("customerNo:" + customerNo + ",mobileMost: " + mobileMost + ", encryptMobileMost: " + encryptMobileMost + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobileMost).append(",");
				}
				if(StringUtils.isNotBlank(phoneMost)){
					encryptPhoneMost = CryptTools.encrypt(phoneMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhoneMost).append("')");

					if(!phoneList.contains(phoneMost)){
						phoneList.add(phoneMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_dd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phoneMost).append("','").append(encryptPhoneMost).append("')");
						insertSt.addBatch(phoneSql.toString());
						//System.out.println("customerNo:" + customerNo + ",phoneMost: " + phoneMost + ", encryptPhoneMost: " + encryptPhoneMost + ", " + phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhoneMost).append(")");
				}
				insertSt.addBatch(infoSql.toString());
				//System.out.println("dd infosql: " + infoSql.toString());
				if(count % COMMIT_NUMBER == 0){
					insertSt.executeBatch();
					conn.commit();
					insertSt.clearBatch();
					logger.info("当当提交客户信息数据. count: " + count);
					count=1;
				}
				if(count%CLAEN_NUMBER == 0){
					phoneList.clear();
				}
				count++;
			}
			insertSt.executeBatch();
			conn.commit();
			insertSt.clearBatch();
			long end = System.currentTimeMillis();
			logger.info("增量加密当当客户信息结束,耗时: " + (end -start)/1000 + "s");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("增量加密当当客户信息失败. " + e.getMessage());
			throw e;
		}finally{
			phoneList.clear();
			phoneList = null;
			ConnectionUtil.newInstance().close(ps, rs);
			ConnectionUtil.newInstance().closeStatement(insertSt);
		}
	}

	public static void encrytYhdData(Connection conn)throws Exception{
		PreparedStatement ps = null;
		Statement insertSt = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		StringBuffer infoSql = null;
		StringBuffer phoneSql = null;
		logger.info("增量加密一号店客户信息开始");
		long start = System.currentTimeMillis();
		List<String> phoneList = Lists.newArrayList();
		int count = 1;
		try {
			sql.append("select customerno,full_name,mobile,phone,fullname_most,mobile_most,phone_most ");
			sql.append("from plt_yhd_customer pdc  ");
			sql.append("where not exists (  ");
			sql.append("select customerno  ");
			sql.append("from tb_yhd_customer_info tc  ");
			sql.append("where  pdc.customerno  = tc.customerno)   ");
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			insertSt = conn.createStatement();
			conn.setAutoCommit(false);
			while(rs.next()){
				infoSql = new StringBuffer();
				phoneSql = new StringBuffer();

				String customerNo = rs.getString("customerno");
				String fullName = rs.getString("full_name");
				String mobile = rs.getString("mobile");
				String phone = rs.getString("phone");
				String fullNameMost = rs.getString("fullname_most");
				String mobileMost = rs.getString("mobile_most");
				String phoneMost = rs.getString("phone_most");

				String encryptCustomerNo = null;
				String encryptFullName = null;
				String encryptMobile = null;
				String encryptPhone = null;
				String encryptFullNameMost = null;
				String encryptMobileMost = null;
				String encryptPhoneMost = null;
				infoSql.append("insert ignore into tb_yhd_customer_info(customerno,customerno_encrypt,full_name_encrypt, mobile_encrypt,phone_encrypt,fullname_most_encrypt,mobile_most_encrypt,phone_most_encrypt)");
				infoSql.append("values('");

				encryptCustomerNo = CryptTools.encrypt(customerNo, CryptTools.TYPE_NICK);
				infoSql.append(customerNo).append("','").append(encryptCustomerNo).append("',");
				if(fullName != null){
					encryptFullName = CryptTools.encrypt(fullName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullName).append("',");
				}else{
					infoSql.append(encryptFullName).append(",");
				}
				if(StringUtils.isNotBlank(mobile)){
					encryptMobile = CryptTools.encrypt(mobile, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobile).append("',");

					if(!phoneList.contains(mobile)){
						phoneList.add(mobile);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_yhd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobile).append("','").append(encryptMobile).append("')");
						insertSt.addBatch(phoneSql.toString());
					}

				}else{
					infoSql.append(encryptMobile).append(",");
				}
				if(StringUtils.isNotBlank(phone)){
					encryptPhone = CryptTools.encrypt(phone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhone).append("',");

					if(!phoneList.contains(phone)){
						phoneList.add(phone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_yhd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phone).append("','").append(encryptPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhone).append(",");
				}

				if(fullNameMost != null){
					encryptFullNameMost = CryptTools.encrypt(fullNameMost, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptFullNameMost).append("',");
				}else{
					infoSql.append(encryptFullNameMost).append(",");
				}
				if(StringUtils.isNotBlank(mobileMost)){
					encryptMobileMost = CryptTools.encrypt(mobileMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptMobileMost).append("',");

					if(!phoneList.contains(mobileMost)){
						phoneList.add(mobileMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_yhd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(mobileMost).append("','").append(encryptMobileMost).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptMobileMost).append(",");
				}
				if(StringUtils.isNotBlank(phoneMost)){
					encryptPhoneMost = CryptTools.encrypt(phoneMost, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptPhoneMost).append("')");

					if(!phoneList.contains(phoneMost)){
						phoneList.add(phoneMost);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_yhd_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(phoneMost).append("','").append(encryptPhoneMost).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptPhoneMost).append(")");
				}
				System.out.println("yhd infosql: " + infoSql.toString());
				insertSt.addBatch(infoSql.toString());
				if(count % COMMIT_NUMBER == 0){
					insertSt.executeBatch();
					conn.commit();
					insertSt.clearBatch();
					logger.info("一号店提交客户信息数据. count: " + count);
					count=1;
				}
				if(count%CLAEN_NUMBER == 0){
					phoneList.clear();
				}
				count++;
			}
			insertSt.executeBatch();
			conn.commit();
			insertSt.clearBatch();
			long end = System.currentTimeMillis();
			logger.info("增量加密一号店客户信息结束,耗时: " + (end -start)/1000 + "s");
		} catch (Exception e) {
			conn.rollback();
			e.printStackTrace();
			logger.error("增量加密一号店客户信息数据失败. " + e.getMessage());
			throw e;
		}finally{
			phoneList.clear();
			phoneList = null;
			ConnectionUtil.newInstance().close(ps, rs);
			ConnectionUtil.newInstance().closeStatement(insertSt);
		}
	}

	public static void encrytSuningData(Connection conn)throws Exception{
		PreparedStatement ps = null;
		Statement insertSt = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		StringBuffer infoSql = null;
		StringBuffer phoneSql = null;
		logger.info("增量加密苏宁客户信息开始");
		long start = System.currentTimeMillis();
		List<String> phoneList = Lists.newArrayList();
		int count = 1;
		try {
			sql.append("select customerno,customer_name,customer_name_modify,customer_phone,customer_phone_modify,invoice_recipient_name,invoice_recipient_phone,invoice_recipient_hand_phone ");
			sql.append("from plt_suning_customer pdc  ");
			sql.append("where not exists (  ");
			sql.append("select customerno  ");
			sql.append("from tb_suning_customer_info tc  ");
			sql.append("where  pdc.customerno  = tc.customerno)   ");
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			insertSt = conn.createStatement();
			conn.setAutoCommit(false);
			while(rs.next()){
				infoSql = new StringBuffer();
				phoneSql = new StringBuffer();

				String customerNo = rs.getString("customerno");
				String customerName = rs.getString("customer_name");
				String customerNameModify = rs.getString("customer_name_modify");
				String customerPhone = rs.getString("customer_phone");
				String customerPhoneModify = rs.getString("customer_phone_modify");
				String invoiceRecipientName = rs.getString("invoice_recipient_name");
				String invoiceRecipientPhone = rs.getString("invoice_recipient_phone");
				String invoiceRecipientHandPhone = rs.getString("invoice_recipient_hand_phone");

				String encryptCustomerNo = null;
				String encryptCustomerName = null;
				String encryptCustomerNameModify = null;
				String encryptCustomerPhone = null;
				String encryptCustomerPhoneModify = null;
				String encryptInvoiceRecipientName = null;
				String encryptInvoiceRecipientPhone = null;
				String encryptInvoiceRecipientHandPhone = null;
				infoSql.append("insert ignore into tb_suning_customer_info(customerno,customerno_encrypt,customer_name_encrypt, customer_name_modify_encrypt, ");
				infoSql.append("customer_phone_encrypt,customer_phone_modify_encrypt, invoice_recipient_name_encrypt,invoice_recipient_phone_encrypt, invoice_recipient_hand_phone_encrypt)");
				infoSql.append("values('");

				encryptCustomerNo = CryptTools.encrypt(customerNo, CryptTools.TYPE_NICK);
				infoSql.append(customerNo).append("','").append(encryptCustomerNo).append("',");
				if(customerName != null){
					encryptCustomerName = CryptTools.encrypt(customerName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptCustomerName).append("',");
				}else{
					infoSql.append(encryptCustomerName).append(",");
				}
				if(customerNameModify != null){
					encryptCustomerNameModify = CryptTools.encrypt(customerNameModify, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptCustomerNameModify).append("',");
				}else{
					infoSql.append(encryptCustomerNameModify).append(",");
				}
				if(StringUtils.isNotBlank(customerPhone)){
					encryptCustomerPhone = CryptTools.encrypt(customerPhone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptCustomerPhone).append("',");

					if(!phoneList.contains(customerPhone)){
						phoneList.add(customerPhone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_suning_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(customerPhone).append("','").append(encryptCustomerPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptCustomerPhone).append(",");
				}
				if(StringUtils.isNotBlank(customerPhoneModify)){
					encryptCustomerPhoneModify = CryptTools.encrypt(customerPhoneModify, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptCustomerPhoneModify).append("',");

					if(!phoneList.contains(customerPhoneModify)){
						phoneList.add(customerPhoneModify);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_suning_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(customerPhoneModify).append("','").append(encryptCustomerPhoneModify).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptCustomerPhoneModify).append(",");
				}
				if(invoiceRecipientName != null){
					encryptInvoiceRecipientName = CryptTools.encrypt(invoiceRecipientName, CryptTools.TYPE_RECEIVER_NAME);
					infoSql.append("'").append(encryptInvoiceRecipientName).append("',");
				}else{
					infoSql.append(encryptInvoiceRecipientName).append(",");
				}
				if(StringUtils.isNotBlank(invoiceRecipientPhone)){
					encryptInvoiceRecipientPhone = CryptTools.encrypt(invoiceRecipientPhone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptInvoiceRecipientPhone).append("',");

					if(!phoneList.contains(invoiceRecipientPhone)){
						phoneList.add(invoiceRecipientPhone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_suning_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(invoiceRecipientPhone).append("','").append(encryptInvoiceRecipientPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptInvoiceRecipientPhone).append(",");
				}
				if(StringUtils.isNotBlank(invoiceRecipientHandPhone)){
					encryptInvoiceRecipientHandPhone = CryptTools.encrypt(invoiceRecipientHandPhone, CryptTools.TYPE_PHONE);
					infoSql.append("'").append(encryptInvoiceRecipientHandPhone).append("')");

					if(!phoneList.contains(invoiceRecipientHandPhone)){
						phoneList.add(invoiceRecipientHandPhone);
						phoneSql = new StringBuffer();
						phoneSql.append("insert ignore into tb_suning_customer_phone(phone,phone_encrypt)");
						phoneSql.append("values('").append(invoiceRecipientHandPhone).append("','").append(encryptInvoiceRecipientHandPhone).append("')");
						insertSt.addBatch(phoneSql.toString());
					}
				}else{
					infoSql.append(encryptInvoiceRecipientHandPhone).append(")");
				}
				insertSt.addBatch(infoSql.toString());
				System.out.println("suning infosql: " + infoSql.toString());
				if(count % COMMIT_NUMBER == 0){
					insertSt.executeBatch();
					conn.commit();
					insertSt.clearBatch();
					logger.info("苏宁提交客户信息数据. count: " + count);
					count=1;
				}
				if(count%CLAEN_NUMBER == 0){
					phoneList.clear();
				}
				count++;
			}
		 	insertSt.executeBatch();
			conn.commit();
			insertSt.clearBatch();
			long end = System.currentTimeMillis();
			logger.info("增量加密苏宁客户信息结束,耗时: " + (end -start)/1000 + "s");
		} catch (Exception e) {
			conn.rollback();
			e.printStackTrace();
			logger.error("增量加密苏宁客户信息数据失败. " + e.getMessage());
			throw e;
		}finally{
			ConnectionUtil.newInstance().close(ps, rs);
			ConnectionUtil.newInstance().closeStatement(insertSt);
		}
	}
}
